﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;

namespace K19T2_T133747_PhucTran_LabAssignment04.Tests
{
    /// <summary>
    /// Summary description for UnitTest1
    /// </summary>
    [TestFixture]
    public class AverageTest
    {
        CalcAverage _average;

        [Test]
        public void CalcAverage_WithFirstValueEqualNegative999_ShouldThrowValueNegative999()
        {
            int[] temp = new int[] { -999, 1, 2 };
            int minimum = 1;
            int maximum = 10;
            _average = new CalcAverage();
            float expectedvalue = -999;
            float actualvalue = _average.average(temp, minimum, maximum);
            Assert.AreEqual(expectedvalue, actualvalue);
        }

        [Test]
        public void CalcAverage_WithValidNumberLessThanZero_ShouldThrowValueNegative999()
        {
            int[] temp = new int[] { 1, 2, 3 };
            int minimum = 5;
            int maximum = 10;
            _average = new CalcAverage();
            float expectedvalue = -999;
            float actualvalue = _average.average(temp, minimum, maximum);
            Assert.AreEqual(expectedvalue, actualvalue);
        }

        [Test]
        public void CalcAverage_WithAllValueGreaterThanMaximumOrLessThanMinimum_ShouldThrowValueNegative999()
        {
            int[] temp = new int[] { 11, 12, 13 };
            int minimum = 5;
            int maximum = 10;
            _average = new CalcAverage();
            float expectedvalue = -999;
            float actualvalue = _average.average(temp, minimum, maximum);
            Assert.AreEqual(expectedvalue, actualvalue);
        }

        [Test]
        [ExpectedException(typeof(IndexOutOfRangeException))]
        public void CalcAverage_WithEndValueNotEqualNegative999_ShouldThrowIndexOutOfRangeException()
        {
            int[] temp = new int[] { 1, 2, 3 };
            int minimum = 1;
            int maximum = 10;
            _average = new CalcAverage();
            float expectedvalue = 2;
            float actualvalue = _average.average(temp, minimum, maximum);
            Assert.AreEqual(expectedvalue, actualvalue);
        }

        [Test]
        public void CalcAverage_WithAllValueValid_ShouldReturnValidResult()
        {
            int[] temp = new int[] { 1, 2, 3, -999 };
            int minimum = 1;
            int maximum = 10;
            _average = new CalcAverage();
            float expectedvalue = 2;
            float actualvalue = _average.average(temp, minimum, maximum);
            Assert.AreEqual(expectedvalue, actualvalue);
        }
    }
}
